﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//Author: ljj
//Date: 20190624
//Function: 减速debuff effect越大,速度越小
public class Slow : BaseBuff
{
    public override void BuffUp()
    {
        //Debug.Log("Slow BuffUp" + effect);
        UpdateSpeed(this.effect);
        BodyColor body = gameObject.GetComponentInChildren<BodyColor>();
        if (body != null)
            body.AddColor(new Color(21f / 255f, 105f / 255f, 255f / 255f));
    }

    public override void BuffDown()
    {
        //Debug.Log("Slow BuffDown" + effect);
        UpdateSpeed(1.0f / this.effect);
        BodyColor body = gameObject.GetComponentInChildren<BodyColor>();
        if (body != null)
            body.ReplaceColor(new Color(1f, 1f, 1f));
    }

    void UpdateSpeed(float effect)
    {
        Move move = gameObject.GetComponent<Move>();
        if (move != null)
            move.speed /= effect;
        Player player = gameObject.GetComponent<Player>();
        if (player != null)
            player.speed /= effect;
        BattleObject battle = gameObject.GetComponent<BattleObject>();
        if (battle != null)
        {
            battle.coolTime *= effect;
            battle.frontActionTime *= effect;
            battle.attackActionTime *= effect;
            battle.afterActionTime *= effect;
            battle.UpdateAnimatorSpeed();
        }
    }
}
